<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:if test="role.roleId==null"><s:text name="role.add.title"/></s:if><s:else><s:text name="role.edit.title"/></s:else></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
<!--[if IE 6]>
<script type="text/javascript" src="${ctx}/js/DD_belatedPNG.js" ></script><script type="text/javascript">
DD_belatedPNG.fix('.templateNav a');
</script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<div id="main_box">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="templateEditor"/></div>
	<div class="listtit"><p><span><strong><s:text name="templateEditor"/></strong></span></p></div>
	<div class="template">
		<s:form  id="tpl_form" >
			<div class="templateCon">
				<p><s:text name="templateName"/>：<s:hidden name="bean.parentPath" /><s:hidden name="bean.path" id="beanPath" required="true" requiredposition="right" cssClass="txtin" readonly="true"/></p>
				<p><s:textfield name="bean.name" id="beanName" required="true" requiredposition="right" cssClass="txtin" readonly="true"/></p>
				<p><s:text name="parameterCode"/>：</p>
				<p> 
				<s:textarea name="bean.content" id="beanContent" cssClass="template-code" onclick="tellPoint();"></s:textarea>
				<s:hidden id="text_start" value="0"/>
				<s:hidden  id="text_end" value="0"/>
				<s:hidden id="hidden_prefix" name="prefix" />
				<s:hidden id="hidden_suffix" name="suffix" />
				<s:hidden id="hidden_type"  name="type" />
				<s:hidden id="hidden_contentType" name="contentType" />
				<s:hidden name="selected" id="hidden_selected"/>
				</p>
				<p class="m6">
					    <s:hidden  name="assoFlag"/>
					    <s:if test="%{authLicence('1_1_6')}"> 
						    <input type="button" value="<s:text name="submit"/>" Class="btnlist2" id="tpl_submit"/>
						</s:if>
						<s:else> <input disabled="disabled" type="button" value="<s:text name="submit"/>" Class="btnlist2" id="tpl_submit"/></s:else>
						<s:reset value="%{getText('reset')}" cssClass="btnlist2"/>
						<input type="button" value="<s:text name="return"/>" Class="btnlist2" id="tpl_back" onclick="javascript:history.back()"/>
				</p>
			</div>
		</s:form>
		<div class="templateNav">
			<dl>
				<dt><s:text name="pageComponents"/></dt>
				<dd id="showdiv"><a href="###" name="component_href" id="rollannounce" class="ad"><s:text name="announcementRoll"/></a></dd>
				<dd id="showdiv2"><a href="###"  name="component_href" id="rotate" class="img"><s:text name="carouselComponent"/></a></dd>
				<dd id="showdiv3"><a href="###"  name="component_href" id="association" class="element"><s:text name="associatedComponents"/></a></dd>
				<dd id="showdiv4"><a href="###"  name="component_href" id="pagination" class="pop"><s:text name="componentsTabs"/></a></dd>
				<dd id="showdiv5"><a href="###"  name="component_href" id="site_cat_nav" class="nav"><s:text name="navigationComponents"/></a></dd>
				<dd id="showdiv6"><a href="###"  name="component_href" id="cateFrame" class="list"><s:text name="partFrameworkComponents"/></a></dd>
				<dd id="showdiv7"><a href="###"  name="component_href" id="crumbs" class="crumbs"><s:text name="breadCrumbsNavigation"/></a></dd>
				<dd id="showdiv8"><a href="###" name="component_href" id="leftTree" class="mlist"><s:text name="leftTreePage"/></a></dd>
				<%-- <dd ><a href="###"  name="component_href" class="element"><s:text name="articlesEelements"/></a></dd>
				<dd><a href="###"  name="component_href" class="link"><s:text name="friendlyLink"/></a></dd>
				<dd><a href="###"  name="component_href" class="hot"><s:text name="headlines"/></a></dd>
				<dd><a href="###"  name="component_href" class="list"><s:text name="articleList"/></a></dd>
				<dd><a href="###"  name="component_href" class="pop"><s:text name="pageComponents"/></a></dd>
				<dd><a href="###"  name="component_href" class="img"><s:text name="scrollImage"/></a></dd>
				<dd><a href="###"  name="component_href" class="proj"><s:text name="scrollingPictureItems"/></a></dd>
				<dd><a href="###"  name="component_href" class="mlist"><s:text name="moreArticlesList"/></a></dd>
				<dd><a href="###"  name="component_href" class="toplist"><s:text name="systemTopList"/></a></dd>
				<dd><a href="###"  name="component_href" class="special"><s:text name="featurearticles"/></a></dd>
				<dd><a href="###"  name="component_href" class="nav"><s:text name="navigation"/></a></dd>
				<dd><a href="###"  name="component_href" class="map"><s:text name="siteMap"/></a></dd>
				<dd><a href="###"  name="component_href" class="photo"><s:text name="electronicAlbum"/></a></dd>
				<dd><a href="###"  name="component_href" class="slides"><s:text name="slide"/></a></dd>
				<dd><a href="###" name="component_href"  class="ad"><s:text name="advertisement"/></a></dd> --%>
			</dl>
		</div>
		<div class="clear"></div>
	</div>

</div> 
</div>
<div id="lightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose" class="lightclose" /><strong><s:text name="componentEditor"/></strong></span></p></div>
	<div class="lightmain">
		<div id="iframe_parameter">
		</div>
		<div class="lightmaintit m15"><strong><s:text name="previewArea"/></strong>
			<%-- 
			<input type="button" class="viewbtna" value="<s:text name="switchSourceMode"/>"/>
			<input type="button" class="viewbtnb" value="<s:text name="switchviewMode"/>"/> 
			--%>
		</div>
		<div class="lightmainview"  id="component_code_div"></div>		
	</div>
	
</div>
</body>
<script type="text/javascript">
	$(function(){
		$(".templateNav").find("dd").each(function(){
			$(this).click(function(){
				$(".templateNav").find("dd").removeClass("current");
				$(this).addClass("current");
			});
		});
		$("#showdiv").click(function(){
			$$.shadeshowb("#showdiv","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv2").click(function(){
			$$.shadeshowb("#showdiv2","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv3").click(function(){
			$$.shadeshowb("#showdiv3","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv4").click(function(){
			$$.shadeshowb("#showdiv4","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv5").click(function(){
			$$.shadeshowb("#showdiv5","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv6").click(function(){
			$$.shadeshowb("#showdiv6","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv7").click(function(){
			$$.shadeshowb("#showdiv7","#lightclose,#code_insert_btn","#lightbox",400,780);
			$$.shadehidden("#lightclose,#code_insert_btn","#lightbox");
		});
		$("#showdiv8").click(function(){
			$$.shade("#showdiv8","#lightclose,#code_insert_btn","#lightbox",780);
		});
	}); 
	
	// 弹出窗口时加载组件参数信息
	$("a[name='component_href']").each(function(i,item){
		$(item).click(function(){
			$("#component_code_div").html('');
			var type=$(item).attr("id");
			$("#iframe_parameter").html('<iframe style="width:100%;" height=260 frameborder="0" id="component_iframe"   name="component_iframe" ' 
									+' src="${ctx}/component/componentpage.action?componentType='
									+type+'"/>');
		});
	});
	


	// 获取参数 （包含catIDS）
	function getParameters(arr){
		$(window.frames["component_iframe"].document).find('input:text[class="template-arg"]').each(function(i,item){
			var v =$.trim($(item).val()); 
			var name = $.trim($(item).attr("name"));
			arr.push(name);
			if(v && v!=''){
				arr.push(v);
			}else{
				arr.push('-');
			} 
		});
		return arr;
	}
    //加载替换参数后的组件HTML代码
	function loadComponent(type,parameters){
		$.ajax({
			async:false,
			url:"${ctx}/component/loadcomponent.action?t="+new Date().getTime(),
			data:{"componentType":type,"parameters":parameters},		
			dataType:"html",
			type:"post",
			success:function(data){ 
				$("#component_code_div").html(data);
			}
		});
	}
    
    function tellPoint(){  

    	var end = document.getElementById('beanContent').value.length;
    	document.getElementById('text_end').value = end;
    	var aCtrl = document.getElementById("beanContent");
    	if (aCtrl.setSelectionRange) {
    	setTimeout(function() { //将光标定位在textarea的开头，需要定位到其他位置的请自行修改
    	aCtrl.focus();
    	document.getElementById("text_start").value = aCtrl.selectionStart;
    	}, 0);
    	}else if (aCtrl.createTextRange) {
        var rng = event.srcElement.createTextRange();
        rng.moveToPoint(event.x,event.y); 
        rng.moveStart("character",-event.srcElement.value.length); 
        document.getElementById("text_start").value = rng.text.length;
    	}
    	
    	
    }

	function finalf(){
    	var insert = $("#component_code_div").text();  
    	if(insert){    
	    	var content = $.trim($("#beanContent").val());
	    	var end =$("#text_end").val();						 
	    	var start =$("#text_start").val();	  
	    	if(end != 0){	    		
		    	var s_c = content.substr(0,start);    				 
		    	var e_c = content.substr(start,end);       			  
		    	$("#beanContent").val(s_c+insert+e_c);
	    	}else{  
	    		$("#beanContent").val(content+insert);
	    	}
    	} 
    	$("#lightclose").trigger("click");
	}
 
 
</script>
<script src="${ctx}/js/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
   $("#tpl_submit").click(checkForm);
   
   function submitForm(){
	   $("#tpl_form").ajaxSubmit({
		   	url:"${ctx}/theme/file-edit.action?t="+new Date().getTime(),
		   	type:"post",
		    dataType:"text",
		    success:function(data){
		    	var json = eval('('+data+')'); 
		    	if(json.flag){
		    		alert(json.msg);
		    		window.location.href="${ctx}/theme/file-manage.action?mark=down&crruentpath="+json.oldPath;		    		 
		    	}else{
		    		alert(json.msg);
		    	}
		    }
	   });
   }
   
   function selectSubmitForm(){
	   $("#tpl_form").ajaxSubmit({
		   	url:"${ctx}/theme/file-update.action?t="+new Date().getTime(),
		   	type:"post",
		    dataType:"text",
		    success:function(data){
		    	var json = eval('('+data+')'); 
		    	if(json.flag){
		    		alert(json.msg);
		    		window.location.href="${ctx}/theme/file-select.action?t="+new Date().getTime()
		    				+"&type="+$("#hidden_type").val()+"&prefix="+$("#hidden_prefix").val()
		    				+"&suffix="+$("#hidden_suffix").val()+"&contentType="+$("#hidden_contentType").val()+"&selected="+$("#hidden_selected").val();		    		 
		    	}else{
		    		alert(json.msg);
		    	}
		    }
	   });
   }
   
   function  checkForm(){
	   var content = $("#beanContent").val() ;
	   if(content && content !='' && $.trim(content)!=''){
		   var prefix = $("#hidden_prefix").val();
		   var suffix = $("#hidden_suffix").val(); 
		   var type = $("#hidden_type").val();
		   var contentType = $("#hidden_contentType").val();		   
	       if(prefix!='' || suffix!='' || type!='' || contentType!=''){   
			   selectSubmitForm();
		   }else{
			   submitForm();		    
		   } 
	   }else{
		   alert('请输入内容');
	   }   
   } 
</script>

